package com.sigmazero13.gameutils.widgets;

import java.util.List;

import android.content.Context;
import android.util.AttributeSet;

import com.sigmazero13.components.MultiRowInput;
import com.sigmazero13.gameutils.model.GamePlayerInfo;

public class MultiPlayerEntry extends MultiRowInput<PlayerEntryView> {
	
	public List<String> playerList;
	public List<String> usernameList;
	public List<String> teamList;

	protected class PlayerEntryFactory implements InputFactory<PlayerEntryView> {
		@Override
		public PlayerEntryView create(Context context) {
			PlayerEntryView newView = new PlayerEntryView(context);
			newView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
			newView.setPlayerList(playerList);
			newView.setUsernameList(usernameList);
			newView.setTeamList(teamList);
			newView.toggleExpand();
			return newView;
		}
	}
	
	public MultiPlayerEntry(Context context) {
		super(context);
		this.attachFactory(new PlayerEntryFactory());
	}
	
	public MultiPlayerEntry(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.attachFactory(new PlayerEntryFactory());
	}
	
	public void setPlayerList(List<String> playerList) {
		this.playerList = playerList;
	}
	
	public void setUsernameList(List<String> usernameList) {
		this.usernameList = usernameList;
	}
	
	public void setTeamList(List<String> teamList) {
		this.teamList = teamList;
		for (PlayerEntryView pView : inputs) {
			pView.setTeamList(teamList);
		}
	}
	
	public void setPlayerInfo(List<GamePlayerInfo> players) {
		this.deleteAllRows();
		for (GamePlayerInfo player : players) {
			PlayerEntryView pev = addNewInput();
			pev.setPlayerInfo(player);
		}
	}
}
